package com.imau.servlet;

import com.alibaba.fastjson.JSON;
import com.imau.bean.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet(name = "AxiosServlet2", value = "/axiosServlet2")
public class AxiosServlet2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //获取前端发送JSON数据
        BufferedReader reader = request.getReader();
        String s = reader.readLine();

        //JSON串数据转成Java对象
        User user = JSON.parseObject(s, User.class);

        System.out.println("user=="+user);

        response.getWriter().write("axiosServlet2");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        this.doGet(request,response);
    }
}
